//
//  XLHintAwardView.m
//  XiangLove
//
//  Created by 李传坤 on 2018/4/17.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#import "XLHintAwardView.h"

@interface XLHintAwardView ()

@property (strong, nonatomic) UIImageView *LeImageView;
@property (strong, nonatomic) UILabel *middleLabel;//恭喜label
@property (strong, nonatomic) UIView *alertView;

@property (strong, nonatomic) UIButton *GoTakeButton;
@property (strong, nonatomic) UIButton *dismissButton;



@end

@implementation XLHintAwardView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        // 设置背影为透明色
        self.backgroundColor = [UIColor clearColor];
        [self addViews];
    }
    return self;
}
- (void)addViews{
    UIView *view = [[UIView alloc]init];
    view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    view.backgroundColor = [UIColor blackColor];
    view.alpha = 0.3;
    [self addSubview:view];
    
    _alertView = [[UIView alloc]init];
    _alertView.backgroundColor = [UIColor clearColor];
    _alertView.layer.cornerRadius = 10;
    _alertView.center = CGPointMake(self.width/2,self.height/2);
    _alertView.frame = CGRectMake(SCREEN_WIDTH/2 - 145, SCREEN_HEIGHT/2 - 120, 290, 240);
    [self addSubview:_alertView];
    
    _LeImageView = [[UIImageView alloc]init];
    _LeImageView.frame = CGRectMake(0, 0, _alertView.frame.size.width,_alertView.frame.size.height);
    _LeImageView.image = [UIImage imageNamed:@"Views_bg_jiangli_n"];
    [_alertView addSubview:_LeImageView];
    
    _middleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, _alertView.frame.size.height - 90, 280, 20)];
    _middleLabel.text = @"你有奖励未领取";
    _middleLabel.textColor = [UIColor whiteColor];
    _middleLabel.textAlignment = NSTextAlignmentCenter;
    _middleLabel.font = [UIFont systemFontOfSize:19];
    [_alertView addSubview:_middleLabel];
    
    _dismissButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_dismissButton setBackgroundImage:[UIImage imageNamed:@"Views_bg_jiangli_chacha_n"] forState:UIControlStateNormal];
    [_dismissButton addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
    [self.alertView addSubview:_dismissButton];
    [_dismissButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_LeImageView.mas_top);
        make.right.equalTo (_LeImageView.mas_right);
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    
    _GoTakeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_GoTakeButton addTarget:self action:@selector(push) forControlEvents:UIControlEventTouchUpInside];
    [_GoTakeButton setTitle:@"马上领取" forState:UIControlStateNormal];
    _GoTakeButton.backgroundColor = RGB_HEX(0xFFD106);
    _GoTakeButton.layer.cornerRadius = 20;
    [self.alertView addSubview:_GoTakeButton];
    [_GoTakeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_LeImageView.mas_centerX);
        make.top.equalTo (_LeImageView.mas_top).offset(185);
        make.size.mas_equalTo(CGSizeMake(130, 40));
    }];
    
}
- (void)push{
    [self dismiss];
    _block();
    
}
-(void)show{
    [[[[UIApplication sharedApplication]delegate]window]addSubview:self];
}
-(void)dismiss{
    [UIView animateWithDuration:0.3
                          delay:0.0
                        options: UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         self.alpha = 0;
                     }
                     completion:^(BOOL finished){
                         [self removeFromSuperview];
                     }];
}


@end
